package org.dwpd.controller.user;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.dwpd.domain.common.Result;
import org.dwpd.domain.user.User;
import org.dwpd.domain.user.UserInfo;
import org.dwpd.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;


    /**
     * 根据用户Id获取当前登录用户信息
     */
    @GetMapping("/getUserDetailById")
    public Result getUserDetailById() {
        return userService.getUserDetailById();
    }

    /**
     * 根据用户Id获取指定用户信息
     */
    @GetMapping("/getUserDetailByUserId")
    public Result getUserDetailByUserId(Integer userId) {
        return userService.getUserDetailByUserId(userId);
    }


    /**
     * 修改用户个人信息
     */
    @PostMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody UserInfo userInfo, HttpServletRequest request) {
        return userService.updateUserInfo(userInfo, request);
    }

    /**
     * 获取指定用户帖中的上座用户信息
     */
    @GetMapping("/queryOnSeatUsers")
    public Result queryOnSeatUsers(Integer messageId) {
        return userService.queryOnSeatUsers(messageId);
    }

    /**
     * 修改用户头像
     * @param userImage 用户头像
     */
    @PostMapping("/updateUserImage")
    public Result updateUserImage(String userImage, HttpServletRequest request) {
        return userService.updateImage(userImage, request);
    }

    /**
     * 注册用户
     */
    @PostMapping({"regist"})
    public Result regist(@RequestBody User user, HttpServletRequest request) {
        String code = request.getHeader("emailCode");
        return userService.regist(user,code);
    }

    /**
     * 获取验证码
     */
    @GetMapping({"reqEmailCode"})
    public Result reqEmailCode(String email) {
        return userService.getMailCode(email);
    }

    /**
     * 用户登录
     */
    @PostMapping({"login"})
    public Result login(@RequestBody User user,HttpServletRequest request) {
        return this.userService.login(user, request);
    }

    /**
     * 忘记密码
     */
    @PostMapping({"forgetPassword"})
    public Result forgetPwd(@RequestBody User user, HttpServletRequest request) {
        String emailCode = request.getHeader("emailCode");
        return this.userService.modifyPassword(user,emailCode);
    }


}
